/* pages/"columnChart/columnChart.js */
const app = getApp();
var rate = 0;
var canvasWidth = 0;
var canvasHeight = 0;
var tiback = app.globalData._network_path + 'tiback.png';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tiback: tiback,//背景图
    columnCanvasData: {
      canvasId: 'columnCanvas',
      equipment_id: '',
      info: {}
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var equipment_id = options.equipment_id;
    this.setData({
      equipment_id: equipment_id
    })
    

  },
  //水量统计
  detail() {
    var that = this;
    app.ajax({
      url: "User/Equipmentlists/getWaterStatistics",
      data: { "equipment_id": that.data.equipment_id },
      success: function (res) {
        if (res.data.code == 1000) {
    
          that.setData({
            info: res.data.data
          })
          that.draw(res.data.data.seven.step*7);
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.detail();
  },
  draw:function(steps){
    var systemInfo = app.systemInfo;
    rate = systemInfo.screenWidth / 750;
    var updateData = {};
    canvasWidth = systemInfo.screenWidth - rate * 64;
    canvasHeight = rate * 306 + rate * 44 + rate * 34 + rate * 22;

    var culumnYMax = steps;
    var culumnYMin = 0;
    updateData['columnCanvasData.canvasWidth'] = canvasWidth;
    updateData['columnCanvasData.axisPadd'] = { left: rate * 5, top: rate * 13, right: rate * 5 };
    updateData['columnCanvasData.axisMargin'] = { bottom: rate * 34, left: rate * 26 };
    updateData['columnCanvasData.yAxis.fontSize'] = rate * 22;
    updateData['columnCanvasData.yAxis.fontColor'] = '#637280';
    updateData['columnCanvasData.yAxis.lineColor'] = '#95B8E9';
    updateData['columnCanvasData.yAxis.lineWidth'] = rate * 3;
    updateData['columnCanvasData.yAxis.dataWidth'] = rate * 39;
    updateData['columnCanvasData.yAxis.isShow'] = true;
    updateData['columnCanvasData.yAxis.isDash'] = true;
    updateData['columnCanvasData.yAxis.minData'] = culumnYMin;
    updateData['columnCanvasData.yAxis.maxData'] = culumnYMax;
    updateData['columnCanvasData.yAxis.padd'] = rate * 306 / (culumnYMax - culumnYMin);

    updateData['columnCanvasData.xAxis.dataHeight'] = rate * 26;
    updateData['columnCanvasData.xAxis.fontSize'] = rate * 22;
    updateData['columnCanvasData.xAxis.fontColor'] = '#637280';
    updateData['columnCanvasData.xAxis.lineColor'] = '#95B8E9';
    updateData['columnCanvasData.xAxis.lineWidth'] = rate * 3;
    updateData['columnCanvasData.xAxis.padd'] = rate * 52;
    updateData['columnCanvasData.xAxis.dataWidth'] = rate * 39;
    updateData['columnCanvasData.xAxis.leftOffset'] = rate * 20;


    updateData['columnCanvasData.canvasHeight'] = canvasHeight;
    updateData['columnCanvasData.enableScroll'] = true;

    this.setData(updateData);
    this.setViewData();
  },
  //赋值
  setViewData() {
    var updateData = {};
    var columnYMax = this.data.info.seven.step * 7;
    var columnYMin = 0;
    updateData['columnCanvasData.yAxis.minData'] = columnYMin;
    updateData['columnCanvasData.yAxis.maxData'] = columnYMax;
    updateData['columnCanvasData.series'] = [{
      data: this.data.info.seven.y,
    }];
    updateData['columnCanvasData.xAxis.data'] = this.data.info.seven.x;
    updateData['columnCanvasData.yAxis.data'] = [
      { x: 0, y: 0, title: 0 },
      { x: 0, y: this.data.info.seven.step, title: this.data.info.seven.step },
      { x: 0, y: this.data.info.seven.step*2, title: this.data.info.seven.step * 2 },
      { x: 0, y: this.data.info.seven.step*3, title: this.data.info.seven.step * 3 },
      { x: 0, y: this.data.info.seven.step*4, title: this.data.info.seven.step * 4 },
      { x: 0, y: this.data.info.seven.step*5, title: this.data.info.seven.step * 5 },
      { x: 0, y: this.data.info.seven.step*6, title: this.data.info.seven.step * 6 },
      { x: 0, y: this.data.info.seven.step*7, title: this.data.info.seven.step * 7 }
    ];
    this.setData(updateData);
  },
  onTouchHandler(e) {
    if (null == this.column_chart) {
      this.column_chart = this.selectComponent("#column-chart");
    }
    this.column_chart.onTouchHandler(e);
  },
  onTouchMoveHandler(e) {
    if (null == this.column_chart) {
      this.column_chart = this.selectComponent("#column-chart");
    }
    this.column_chart.onTouchMoveHandler(e);
  },
  onTouchEndHandler(e) {
    if (null == this.column_chart) {
      this.ccolumn_chart = this.selectComponent("#column-chart");
    }
    this.column_chart.onTouchEndHandler(e);
  },


})